<script lang="js">
import { computed, defineComponent } from 'vue'

import { useRouter } from 'vue-router'

export default defineComponent({
  name: 'RouteView',
  props: {
    keepAlive: {
      type: Boolean,
      default: true
    }
  },
  data () {
    return {}
  },
  render () {
    const router = useRouter()
    const meta = computed(() => router.currentRoute.value.meta) // 获取当前路由的 meta
    // const { $route: { meta } } = this
    const inKeep = (
        <keep-alive>
          <router-view />
        </keep-alive>
    );
    const notKeep = <router-view />;
    // 这里增加了 multiTab 的判断，当开启了 multiTab 时
    // 应当全部组件皆缓存，否则会导致切换页面后页面还原成原始状态
    // 若确实不需要，可改为 return meta.keepAlive ? inKeep : notKeep
    if (!meta.value.keepAlive) {
      return notKeep;
    }
    return meta.value.keepAlive ? inKeep : notKeep;
  }
})
</script>
